Conditions | 35 |
Total Lines | 111 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like GamePage.render often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import { graphql } from "gatsby" |
||
58 | |||
59 | render() { |
||
60 | if (this.matchId === null) { |
||
61 | return ( |
||
62 | <Layout> |
||
63 | <section className="grid-container site-content">Geen match beschikbaar...</section> |
||
64 | </Layout> |
||
65 | ) |
||
66 | } |
||
67 | |||
68 | moment.tz.setDefault(`Europe/Brussels`) |
||
69 | moment.locale(`nl-be`) |
||
70 | moment.localeData(`nl-be`) |
||
71 | |||
72 | if (this.state.loading === false && this.state.data) { |
||
73 | const { general = {}, substitutes = {}, lineup = {}, events = [] } = this.state.data |
||
74 | const homeTeamId = general.homeClub?.id |
||
75 | const ogImage = { |
||
76 | src: general?.homeClub?.logo, |
||
77 | width: 180, |
||
78 | height: 180, |
||
79 | } |
||
80 | |||
81 | const { home: homeLineup = [], away: awayLineup = [] } = lineup || {} |
||
82 | const { home: homeSubs = [], away: awaySubs = [] } = substitutes || {} |
||
83 | |||
84 | const matchTime = moment(general.date) |
||
85 | |||
86 | return ( |
||
87 | <Layout> |
||
88 | <SEO |
||
89 | lang="nl-BE" |
||
90 | title={`Matchverslag ${general.homeClub?.abbreviation || general?.homeClub?.name} - ${ |
||
91 | general.awayClub?.abbreviation || general?.awayClub?.name |
||
92 | }`} |
||
93 | description={`Matchverslag ${general.homeClub?.abbreviation || general?.homeClub?.name} - ${ |
||
94 | general.awayClub?.abbreviation || general?.awayClub?.name |
||
95 | }`} |
||
96 | path={`/game/${general?.id}`} |
||
97 | image={ogImage} |
||
98 | /> |
||
99 | |||
100 | <section className="grid-container game-stats"> |
||
101 | <div className="grid-x grid-margin-x"> |
||
102 | <div className={`cell large-12 center game__details`}> |
||
103 | <div className="game__teams"> |
||
104 | <div className={`game__teams-inner`}> |
||
105 | <LazyLoad debounce={false}> |
||
106 | <img src={general.homeClub?.logo} alt={general.homeClub?.name} title={general.homeClub?.name} /> |
||
107 | </LazyLoad> |
||
108 | </div> |
||
109 | {this.renderScore(general.goalsHomeTeam, general.goalsAwayTeam)} |
||
110 | <div className={`game__teams-inner`}> |
||
111 | <LazyLoad debounce={false}> |
||
112 | <img src={general.awayClub?.logo} alt={general.awayClub?.name} title={general.awayClub?.name} /> |
||
113 | </LazyLoad> |
||
114 | </div> |
||
115 | </div> |
||
116 | <h1>{`${general.homeClub?.abbreviation || general.homeClub?.name} - ${ |
||
117 | general.awayClub?.abbreviation || general.awayClub?.name |
||
118 | }`}</h1> |
||
119 | <h4>{general.competitionType}</h4> |
||
120 | <time dateTime={matchTime.format(`YYYY-MM-DD - H:mm`)}> |
||
121 | {matchTime.format(`dddd DD MMMM YYYY - H:mm`)} |
||
122 | </time> |
||
123 | <br /> |
||
124 | |||
125 | {general.status !== 0 && ( |
||
126 | <span className={`game__status game__status--${general.status}`}>{mapPsdStatus(general.status)}</span> |
||
127 | )} |
||
128 | |||
129 | <br /> |
||
130 | </div> |
||
131 | {(homeLineup.length !== 0 || awayLineup.length !== 0) && ( |
||
132 | <div className={`lineup__wrapper grid-x grid-margin-x cell large-12`}> |
||
133 | <div className={`cell large-6 lineup__wrapper--home`}> |
||
134 | <h3>{general.homeClub?.abbreviation || general.homeClub?.name}</h3> |
||
135 | {homeLineup && this.renderLineup(homeLineup, homeSubs)} |
||
136 | </div> |
||
137 | <div className={`cell large-6 lineup__wrapper--away`}> |
||
138 | <h3>{general.awayClub?.abbreviation || general.awayClub?.name}</h3> |
||
139 | {awayLineup && this.renderLineup(awayLineup, awaySubs)} |
||
140 | </div> |
||
141 | </div> |
||
142 | )} |
||
143 | |||
144 | {events.length !== 0 && ( |
||
145 | <div className={`cell large-12 event__wrapper`}> |
||
146 | <h3>Gebeurtenissen</h3> |
||
147 | {events && this.renderEvents(events, homeTeamId)} |
||
148 | </div> |
||
149 | )} |
||
150 | </div> |
||
151 | </section> |
||
152 | |||
153 | {general.competitionType === `Competitie` && ( |
||
154 | <MiniRanking |
||
155 | teamId={general.homeTeamId || general.awayTeamId} |
||
156 | homeTeam={general.homeClub?.name} |
||
157 | awayTeam={general.awayClub?.name} |
||
158 | /> |
||
159 | )} |
||
160 | </Layout> |
||
161 | ) |
||
162 | } else { |
||
163 | return ( |
||
164 | <Layout> |
||
165 | <section className="grid-container site-content"> |
||
166 | <Spinner /> |
||
167 | </section> |
||
168 | </Layout> |
||
169 | ) |
||
338 |